.TH std::ranges::views::empty,std::ranges::empty_view 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::ranges::views::empty,std::ranges::empty_view \- std::ranges::views::empty,std::ranges::empty_view

.SH Synopsis
   Defined in header <ranges>
   template<class T>

       requires std::is_object_v<T>                                \fB(1)\fP \fI(since C++20)\fP

   class empty_view : public ranges::view_interface<empty_view<T>>
   namespace views {

       template<class T> inline constexpr empty_view<T> empty{};   \fB(2)\fP \fI(since C++20)\fP

   }

   1) A range factory that produces a view of no elements of a particular type.
   2) Variable template for empty_view.

.SH Member functions

   begin            returns nullptr
   \fB[static]\fP (C++20) \fI(public static member function)\fP
   end              returns nullptr
   \fB[static]\fP (C++20) \fI(public static member function)\fP
   data             returns nullptr
   \fB[static]\fP (C++20) \fI(public static member function)\fP
   size             returns 0 (zero)
   \fB[static]\fP (C++20) \fI(public static member function)\fP
   empty            returns true
   \fB[static]\fP (C++20) \fI(public static member function)\fP
         Inherited from std::ranges::view_interface
   cbegin           returns a constant iterator to the beginning of the range.
   (C++23)          \fI(public member function of std::ranges::view_interface<D>)\fP
   cend             returns a sentinel for the constant iterator of the range.
   (C++23)          \fI(public member function of std::ranges::view_interface<D>)\fP
   operator bool    returns whether the derived view is not empty. Provided if
   (C++20)          ranges::empty is applicable to it.
                    \fI(public member function of std::ranges::view_interface<D>)\fP
   front            returns the first element in the derived view. Provided if it
   (C++20)          satisfies forward_range.
                    \fI(public member function of std::ranges::view_interface<D>)\fP
   back             returns the last element in the derived view. Provided if it
   (C++20)          satisfies bidirectional_range and common_range.
                    \fI(public member function of std::ranges::view_interface<D>)\fP
   operator[]       returns the n^th element in the derived view. Provided if it
   (C++20)          satisfies random_access_range.
                    \fI(public member function of std::ranges::view_interface<D>)\fP

std::ranges::empty_view::begin

   static constexpr T* begin() noexcept { return nullptr; }  \fI(since C++20)\fP

   empty_view does not reference any element.

std::ranges::empty_view::end

   static constexpr T* end() noexcept { return nullptr; }  \fI(since C++20)\fP

   empty_view does not reference any element.

std::ranges::empty_view::data

   static constexpr T* data() noexcept { return nullptr; }  \fI(since C++20)\fP

   empty_view does not reference any element.

std::ranges::empty_view::size

   static constexpr std::size_t size() noexcept { return 0; }  \fI(since C++20)\fP

   empty_view is always empty.

std::ranges::empty_view::empty

   static constexpr bool empty() noexcept { return true; }  \fI(since C++20)\fP

   empty_view is always empty.

   Helper templates

   template<class T>
   inline constexpr bool enable_borrowed_range<ranges::empty_view<T>> =   \fI(since C++20)\fP
   true;

   This specialization of std::ranges::enable_borrowed_range makes empty_view satisfy
   borrowed_range.

.SH Notes

   Although empty_view obtains front, back, and operator[] member functions from
   view_interface, calls to them always result in undefined behavior since an
   empty_view is always empty.

   The inherited operator bool conversion function always returns false.

.SH Example


// Run this code

 #include <ranges>

 int main()
 {
     std::ranges::empty_view<long> e;
     static_assert(std::ranges::empty(e));
     static_assert(0 == e.size());
     static_assert(nullptr == e.data());
     static_assert(nullptr == e.begin());
     static_assert(nullptr == e.end());
 }

.SH See also

   ranges::single_view a view that contains a single element of a specified value
   views::single       \fI(class template)\fP (customization point object)
   (C++20)
   views::all_t        a view that includes all elements of a range
   views::all          (alias template) (range adaptor object)
   (C++20)
   ranges::ref_view    a view of the elements of some other range
   (C++20)             \fI(class template)\fP
